<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${config.mapperPackage}.${info.className}${config.mapperSuffix}">

    <!--${info.tableComment}基础字段-->
    <resultMap id="BaseResultMap" type="${config.modulePackage}.${info.className}${config.moduleSuffix}">
<#list info.columns as tableField>
    <#if tableField.columnKey?? && tableField.columnKey=='PRIMARY'>
        <id column="${tableField.columnName}" jdbcType="${tableField.jdbcType}" property="${tableField.fieldName}"/>
    <#else>
        <result column="${tableField.columnName}" jdbcType="${tableField.jdbcType}" property="${tableField.fieldName}"/>
    </#if>
</#list>
    </resultMap>

    <!--查询${info.tableComment}分页-->
    <select id="page"
            parameterType="${config.modulePackage}.${info.className}${config.moduleSuffix}"
            resultMap="BaseResultMap">
        SELECT
        alias.*
        FROM ${info.tableName} alias
        <where>
            <trim prefixOverrides="AND|OR">
<#list info.columns as tableField>
        <#if tableField.jdbcType?? && tableField.jdbcType=='VARCHAR'>
            <#if tableField.columnKey?? && tableField.columnKey=='PRIMARY'>
            <if test="map.${tableField.fieldName} != null and map.${tableField.fieldName} != ''">
                AND alias.${tableField.columnName} = ${r"#{map."}${tableField.fieldName}${r"}"}
            </if>
            <#else>
            <if test="map.${tableField.fieldName} != null and map.${tableField.fieldName} != ''">
                <bind name="${tableField.fieldName}" value="'%'+map.${tableField.fieldName}+'%'"/>
                AND alias.${tableField.columnName} LIKE ${r"#{"}${tableField.fieldName}${r"}"}
            </if>
            </#if>
        <#else>
            <if test="map.${tableField.fieldName} != null">
                AND alias.${tableField.columnName} = ${r"#{map."}${tableField.fieldName}${r"}"}
            </if>
        </#if>
</#list>
            </trim>
        </where>
    </select>
</mapper>